/* store */
import { useBaseSelectUserStore } from '@src/component/common/BaseSelectUser/store/hooks/base'
/* vue */
import { computed } from 'vue'
/* type */
import { BaseSelectUserGetMarkListModel, BaseSelectUserGetMarkListResult, BaseSelectUserMark } from '@src/component/common/BaseSelectUser/types'
/* model */
import { BaseSelectUserVuexPropertyEnum } from '@src/component/common/BaseSelectUser/store'
import MsgModel from '@model/MsgModel'
/* util */
import { 
  isDepartmentTabByTabType, 
  isRoleTabByTabType, 
  isServiceProviderTabByTabType, 
  isDynamicTabByTabType 
} from '@src/component/common/BaseSelectUser/util'

/** 
 * @description 选人控件的查询标签仓库数据
*/
function useBaseSelectUserStoreMarkList() {
  
  const store = useBaseSelectUserStore()
  const markList = computed(() => store.state.markList)
  
  const setMarkList = (value: BaseSelectUserMark[]) => {
    store.commit(BaseSelectUserVuexPropertyEnum.SetMarkList, value)
  }
  
  return {
    markList,
    setMarkList
  }
}

/** 
 * @description 选人控件的当前标签页
*/
function useBaseSelectUserStoreCurrentTabType() {
  
  const store = useBaseSelectUserStore()
  
  // 当前标签页类型
  const currentTabType = computed(() => store.state.currentTabType)
  
  const setCurrentTabType = (value: string) => {
    store.commit(BaseSelectUserVuexPropertyEnum.SetCurrentTabType, value)
  }
  
  // 当前标签页是否为部门标签
  const isDepartmentTab = computed(() => {
    return isDepartmentTabByTabType(currentTabType.value)
  })
  
  // 当前标签页是否为角色标签
  const isRoleTab = computed(() => {
    return isRoleTabByTabType(currentTabType.value)
  })
  
  // 当前标签页是否为服务商标签
  const isServiceProviderTab = computed(() => {
    return isServiceProviderTabByTabType(currentTabType.value)
  })
  
  // 当前标签页是否为动态获取标签
  const isDynamicTabByTab = computed(() => {
    return isDynamicTabByTabType(currentTabType.value)
  })
  
  return {
    currentTabType,
    isDepartmentTab,
    isRoleTab,
    isServiceProviderTab,
    isDynamicTabByTab,
    setCurrentTabType
  }
}

/** 
 * @description 查询选人控件的查询标签
*/
function useBaseSelectUserStoreFetchMarkList() {
  
  const store = useBaseSelectUserStore()
  
  function fetchMarkList(params: BaseSelectUserGetMarkListModel): Promise<MsgModel<BaseSelectUserGetMarkListResult>> {
    return (
      store.dispatch(BaseSelectUserVuexPropertyEnum.FetchMarkList, params).then(result => {
        return result
      })
    )
  }
  
  return fetchMarkList
}

/**
* @description 查询触发器消息通知选人控件的查询标签
*/
function useBaseSelectUserStoreTriggerFetchMarkList() {
  
  const store = useBaseSelectUserStore()
  
  function fetchMarkList(params: BaseSelectUserGetMarkListModel): Promise<MsgModel<BaseSelectUserGetMarkListResult>> {
    return (
      store.dispatch(BaseSelectUserVuexPropertyEnum.FetchTriggerMarkList, params).then(result => {
        return result
      })
    )
  }
  
  return fetchMarkList
}

export {
  useBaseSelectUserStoreMarkList,
  useBaseSelectUserStoreCurrentTabType,
  useBaseSelectUserStoreTriggerFetchMarkList,
  useBaseSelectUserStoreFetchMarkList
}